package com.kuang.demo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuang.demo.bo.gh.QueryOrderListBO;
import com.kuang.demo.bo.gh.RefundOrderBO;
import com.kuang.demo.bo.gh.ShipOrderBO;
import com.kuang.demo.mapper.OrderMapper;
import com.kuang.demo.vo.OrderDetailVO;
import com.kuang.demo.vo.QueryOrderListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/11/2 22:07
 */
@Service
public class OrderServiceImpl implements OrderService{
    @Autowired
    OrderMapper orderMapper;
    @Override
    public Map<String, Object> queryOrderList(QueryOrderListBO queryOrderListBO) {
        PageHelper.startPage(queryOrderListBO.getPage(),queryOrderListBO.getLimit());
        List<QueryOrderListVO.ItemsBean> itemsBeans = orderMapper.queryOrderList(queryOrderListBO);

        PageInfo<QueryOrderListVO.ItemsBean> itemsBeanPageInfo = new PageInfo<>(itemsBeans);
        Long i = itemsBeanPageInfo.getTotal();
        int total = i.intValue();
        Map<String,Object> brandinfo = new HashMap();
        brandinfo.put("orderList",itemsBeans);
        brandinfo.put("total",total);
        return brandinfo;
    }

    @Override
    public OrderDetailVO queryOrderDetail(Integer id) {
//        private OrderDetailVO.UserBean user;
//        private OrderDetailVO.OrderBean order;
//        private List<OrderDetailVO.OrderGoodsBean>
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        //查询cskaoyanmall_order_goods表获得 List<OrderDetailVO.OrderGoodsBean>
        orderDetailVO.setOrderGoods(orderMapper.queryOrderGoodsBy(id));
        //查询cskaoyanmall_order获得order
        orderDetailVO.setOrder(orderMapper.queryOrderById(id));
        //查询cskaoyanmall_user和cskaoyanmall_order 通过id找到userid找到userinfo

        orderDetailVO.setUser(orderMapper.queryUserInfoById(orderDetailVO.getOrder().getUserId()));
        return orderDetailVO;
    }

    @Override
    public void shipOrder(ShipOrderBO shipOrderBO) {
        orderMapper.shipOrder(shipOrderBO);
    }

    @Override
    public void refundOrder(RefundOrderBO refundOrderBO) {
        orderMapper.refundOrderById(refundOrderBO.getOrderId());
    }
}
